import request from "@/axios"

/**
 * 上传文件
 * @param file
 * @param observer {next:fun,success:fun,error:fun}
 */
export function uploadImg (file, observer) {
    const config = {
        useCdnDomain: true
    }
    const qiniu = require('qiniu-js')
    const observable = qiniu.upload(file, new Date().getTime() + file.name, QI_NIU_TOKEN, null, config)
    observable.subscribe(observer)
}

export const QI_NIU_TOKEN = 'vMgCDi6neP07bVcFtdJ3IW5eLh8XJE-UVZ1-bGdd:PO6_QzfbeJU1oX8_AgcMW2Ci19c=:eyJzY29wZSI6Inlma2oiLCJkZWFkbGluZSI6MTkwMTAwMzE2N30='

export const QI_NIU_URL = 'http://images.zmzpl.com/'
/**
 * 获取分类
 *
 *
 */
export function getTypeList() {
    let url = '/mall/type/queryAll'
    return request.get(url)
}

export function submitGood(goods,saleTypeInfoEntity,types,createTime,goodsQualificationEntity,act) {
    let url = `/api/shop/save`
    let data = {goods,saleTypeInfoEntity,types,createTime,goodsQualificationEntity,act}
    data.json = true
    data.Loading = true
    return request.post(url,data)
}

export function getFormData(id) {
    let url = `/api/shop/info/${id}`
    return request.get(url)
}

export function editGoods(goods,saleTypeInfoEntity,types,createTime,goodsQualificationEntity,act) {
    let url = '/api/shop/update'
    let data = {goods,saleTypeInfoEntity,types,createTime,goodsQualificationEntity,act}
    data.json = true
    data.Loading = true
    return request.post(url,data)
}

export function getLogTem() {
    let url = 'api/shop/shopLogTem'
    return request.post(url)
}